from lxml import etree
#(1)获取网页源码
#(2)解析 解析的服务器响应的文件  etree.html
#(3)打印

import urllib.request
url = 'https://www.baidu.com/'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'
}
#请求对象的定制
request = urllib.request.Request(url=url,headers=headers)
#模拟浏览器向服务器发送请求
response = urllib.request.urlopen(request)
#获取网页源码
content = response.read().decode('utf-8')
#解析网页源码获取想要数据
#解析服务器响应文件
tree = etree.HTML(content)
#获取想要的数据 xpath返回值是列表类型数据
result = tree.xpath('//input[@id = "su"]/@value')[0]

print(result)